package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.Team;
import yxy.cherry.battle.module.affix.AffixContext;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.battle.module.record.stream.RecordStream41TriggerBuff;
import yxy.cherry.data.bean.skill;

import java.util.ArrayList;

/**
 * @author James
 * 盛怒（场上每减少一个（己方或敌方单位），目标怒技增加X%）
 * @date 2022/2/25 12:06
 **/
@BuffType(Type = AffixFactory.BuffTypeEnum.盛怒)
public class Affix76Rage extends Buff {
    public Affix76Rage(Fighter source, Fighter target, skill skilldata, int[] params) {
        super(source, target, skilldata, params);
    }

    private int getCamps() { return getParam(0);}
    private int getAddPer() {return getParam(1);}

    @Override
    public boolean exec(Fighter source, Fighter target) {
        int number = 0;
        if(getCamps() == CAMPS_SELF){
            number = source.getTeam().getDieList().size();
        }else if(getCamps() == CAMPS_OPPONENT){
            number = ((Team)source.getTeam().getTeam对手()).getDieList().size();
        }else if(getCamps() == CAMPS_BOTH){
            number = source.getTeam().getDieList().size() + ((Team)source.getTeam().getTeam对手()).getDieList().size();
        }

        AffixContext.AffixAction affixAction = getAffixAction();
        AffixContext.AffixTarget affixTarget = affixAction.getTarget(affixAction.get针对目标());
        ArrayList<Long> 伤害流 = affixTarget.get伤害流();
        ArrayList<Long> 结算伤害流 = genFinalDamage(伤害流, affixTarget.getBaseDamageList(), getAddPer() * number);

        Battle.battleLogger(6,"盛怒：施法者："+source.getName()+"目标："+target.getName()+"阵营"+getCamps()+"死亡数"+number+"增加值"+getAddPer()+"原始伤害："+伤害流.toString()+"基本伤害："+affixTarget.getBaseDamageList().toString()+"最终伤害："+结算伤害流.toString());

        affixTarget.set伤害流(结算伤害流);

        getRecord().stream(new RecordStream41TriggerBuff(source,source.getBuffMap().get(getBuffCodeSeq()))).record();
        return true;
    }

    @Override
    public BuffType getBuffType() {
        return BuffType.增益效果;
    }

    @Override
    public BuffStateType getBuffStateType() {
        return BuffStateType.rageState;
    }

}
